<template>
  <el-drawer
    v-model="drawer"
    :title="title"
    modal
    :size="size"
    destroy-on-close
    @close="closeDrawer"
  >
    <div class="container">
      <div class="body"><slot></slot></div>
      <div class="btn">
        <el-button type="primary" @click="submit">{{ submitText }}</el-button>
        <el-button @click="closeDrawer">取消</el-button>
      </div>
    </div>
  </el-drawer>
</template>
<script setup>
import { ref } from "vue";
defineProps({
  title: String,
  size: {
    type: String,
    default: "45%",
  },
  submitText: {
    type: String,
    default: "提交",
  },
});
const drawer = ref(false);

const openDrawer = () => (drawer.value = true); // 打开弹框
const closeDrawer = () => (drawer.value = false); // 关闭弹框

// 触发事件传递到父组件中
const emit = defineEmits(["submit"]);
const submit = () => emit("submit");

// 向父组件暴露以下方法
defineExpose({
  openDrawer,
  closeDrawer,
});
</script>

<style>
.container {
  width: 100%;
  height: 100%;
  position: relative;
  @apply flex flex-col;
}
.body {
  flex: 1;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 50px;
  overflow-y: auto;
}
.btn {
  height: 50px;
  @apply mt-auto flex items-center;
}
</style>
